home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1833 / 1833.xpi / modules / yoonoDialogs.js < prev    next >
Text File  |  2009-12-16  |  3KB  |  120 lines

  1. var EXPORTED_SYMBOLS = ["YOONO_DIALOGS"];
  2.  
  3.  
  4. Components.utils.import("resource://yoono/yoonoPrefs.js");
  5.  
  6. // Yoono stuff
  7. var yoono = {};
  8. var log = {info:function() {},debug:function() {},warn:function(){},error:function (){},fatal:function(){}};
  9.  
  10.  
  11. // Vars
  12. const OVERLAYTHROBBER = "yoono-throbber-button";
  13.  
  14. // Globals
  15. const CI = Components.interfaces;
  16. const CL = Components.classes;
  17. const STRBUNDLE = CL["@mozilla.org/intl/stringbundle;1"].getService(CI.nsIStringBundleService);
  18. const WMED = CL['@mozilla.org/appshell/window-mediator;1'].getService(CI.nsIWindowMediator);
  19. const PROMPTS = CL["@mozilla.org/embedcomp/prompt-service;1"].getService(CI.nsIPromptService);
  20.  
  21.  
  22. function Dialogs() {
  23.     this.wrappedJSObject=this;
  24.     
  25.     this._connecting = false;
  26.  
  27.     this.bundle = STRBUNDLE.createBundle('chrome://yoono/locale/yoono.properties');
  28. }
  29.  
  30. Dialogs.prototype.init = function (y) {
  31.     
  32.     yoono=y;
  33.     log=y.log;
  34.     
  35. }
  36.  
  37. Dialogs.prototype.traverseBrowsers = function (fun) {
  38.     var windowsenum = WMED.getEnumerator("navigator:browser");
  39.     var win;
  40.     while (windowsenum.hasMoreElements()) {
  41.         win = windowsenum.getNext();
  42.         fun (win);
  43.     }
  44. },
  45.  
  46. Dialogs.prototype.setDialog = function (name, param) {
  47.     var uri = 'chrome://yoono/content/dialogs/' + name + '.xul';
  48.     win = this.getFirstBrowser();
  49.     win.openDialog(uri, name, 'chrome, modal', param);
  50. },
  51.  
  52. Dialogs.prototype.setThrobberBusy = function (action) {
  53.   return;
  54.     this._connecting = action;
  55.     log.debug('throbber busy, action='+action);
  56.     this.traverseBrowsers (function (win) {
  57.         var el = win.document.getElementById(OVERLAYTHROBBER);
  58.         if (el) {
  59.             el.setAttribute("busy", (action?'true':'false'));
  60.             el.removeAttribute("syncfailed");
  61.         }
  62.     });
  63. },
  64.  
  65. // called in case any request failed or returned bad content.
  66. // beware : not only sync requests ! must check if throbber was busy...
  67. Dialogs.prototype.setThrobberFailed = function () {
  68.   return;
  69.     log.backtrace("FAILED");
  70.     if(this._connecting) {
  71.         log.debug('throbber set to Failed');
  72.         this._connecting = false;
  73.         this.traverseBrowsers (function (win) {
  74.             var el = win.document.getElementById(OVERLAYTHROBBER);
  75.             if (el) {
  76.                 el.setAttribute("busy", 'false');
  77.                 el.setAttribute("syncfailed", 'true');
  78.             }
  79.         });
  80.     }
  81. },
  82.  
  83. // lors de l import, on affiche une boite de dialogue
  84. Dialogs.prototype.warnImport = function (nbr) {
  85.     if (!nbr) return;
  86.     var titlestr = this.bundle.GetStringFromName('warning');
  87.     var textstr = this.bundle.GetStringFromName('import.warning');
  88.     textstr = textstr.replace('%1', nbr);
  89.     return (PROMPTS.confirm(null, titlestr, textstr));
  90. },
  91.  
  92. Dialogs.prototype.synchroinfos = function (action, nbr) {
  93.     var textstr = this.bundle.GetStringFromName('synchroinfos' + action);
  94.     textstr = textstr.replace('%1',nbr);
  95.     this.traverseBrowsers(function(win){win.messageinfos.init('sync', textstr)});
  96. },
  97.  
  98. Dialogs.prototype.notifCallback = function(url) {
  99.     return {
  100.         observe : function (subject, topic, data) {
  101.             if (topic == 'alertclickcallback') {
  102.                 var win = this.getFirstBrowser();
  103.                 if (!win) return;
  104.                 var where = win.whereFromPref(YOONO_PREFS.get('reco.display-mode'));
  105.                 log.debug(where);
  106.                 var recoUrl = YOONO_PREFS.get('serverurl') + 'search.jsp?url=' + url;
  107.                 win.openUILinkIn(recoUrl, where);
  108.             }
  109.         }
  110.     }
  111. },
  112.  
  113. Dialogs.prototype.getFirstBrowser = function () {
  114.     return WMED.getMostRecentWindow("navigator:browser");
  115. }
  116.  
  117.  
  118.  
  119.  
  120. var YOONO_DIALOGS = new Dialogs();